// Manage the files and is wrapper of vpm_algo.h


#ifndef VPM_FILE_H
#define VPM_FILE_H

#include <filesystem>
#include <fstream>
#include <stdlib.h>
#include <string>
#include "vpm_algorithm.h"

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)

#define FILEDIR "db.vpm"
#define VPMDIR "."

#elif __APPLE__ || __linux__ || __unix__

std::string tmp=getenv("HOME");
std::string VPMDIR=tmp+"/"+".local/share/vpm"; // proc in 2 step because i'm retarded
std::string FILEDIR=VPMDIR+"/"+"db.vpm";

#else

#define FILEDIR "db.vpm"
#define VPMDIR "."

#endif


unsigned int Search(std::string title){

  std::filesystem::create_directories(VPMDIR);
  std::ifstream file(FILEDIR);
  
  if(!file.is_open()){
  
    return -1;
  
  }
  
  return VpmParser::Verify::String(file,title);

}

int MaxItems(){

  std::filesystem::create_directories(VPMDIR);
  std::ifstream file(FILEDIR,std::ios::binary);
  
  if(!file.is_open()){
  
    return -1;
  
  }
  
  return VpmParser::Search::MaxItems(file);

}

unsigned int Remove(std::string title){

  std::filesystem::create_directories(VPMDIR);
  std::fstream file(FILEDIR);
  return 0;

}

unsigned int Create(std::string title, std::string desc){

  std::filesystem::create_directories(VPMDIR);
  std::ofstream file(FILEDIR,std::ios::app|std::ios::binary);
  
  if(!file.is_open()){
  
    return -1;
  
  }
  
  VpmModifier::Create(file,title,desc);
  return 0;

}

class Show{

  public:
  
    static std::string Title(std::string title){
    
      std::filesystem::create_directories(VPMDIR);
      std::ifstream file(FILEDIR,std::ios::binary);
      std::string WB;
      std::string result;
      int Items=0;
      return result;

    }
    
    static std::string Number(int number){ // example of modern use
    
      std::filesystem::create_directories(VPMDIR);
      std::ifstream file(FILEDIR,std::ios::binary);
      return VpmParser::Search::Number(file,number);
      
    }

};

#endif
